/*
 * bloom.org 2005 copyright
 */
package org.nanhill.commons.math;

/**
 * @author alin [xalinx at gmail dot com]
 * @date 2006-7-11
 */
public class Power {
	/**
	 * Check the input number is two power.
	 * 
	 * computer store int use complement style
	 * 
	 * e.g:
	 * 
	 * <pre>
	 *    	00000...010  --&gt;  2
	 *    	11111...110  --&gt;  -2
	 *    	00000...010  --&gt;  2&amp;-2(==2)
	 *    	&circ;       &circ;
	 *    	|       |
	 *    	+-30bit-+
	 * </pre>
	 * 
	 * @param n
	 *            input integer.
	 * @return true if input integer is two power, else false.
	 */
	public static boolean isTwoPower(int n) {
		if (0 == n) {
			return true;
		}
		if (0 > n) {
			n = -n;
		}
		if ((n & -n) == n) {
			return true;
		}
		return false;
	}

}
